package com.telenav.module.activities;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.telenav.app.R;
import com.telenav.comm.HostProvider;
import com.telenav.res.image.AsyncImageLoader;

public class ActivityPictures extends Activity{

	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activitypictures);
        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this, getIntent().getStringArrayExtra("images")));
        g.setSelection(this.getIntent().getIntExtra("position", 0));
	}
	
    public class ImageAdapter extends BaseAdapter 
    {
        private Context context;
        private String[] images;
        
        public ImageAdapter(Context c, String[] array) {
            context = c;
            images = array;
        }

        public int getCount() {
            return images.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(context);
            i.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT,
    				Gallery.LayoutParams.FILL_PARENT));
            i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
			AsyncImageLoader.getInstance().loadImage(
					HostProvider.getImageUrl() + "/" + images[position], i,
					R.drawable.noimage1);
            return i;
        }
    }
}
